﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Net;

using Microsoft.Win32;

namespace PmfWeb.Core.Utility
{
    /// <summary>
    /// 用RegistryKey 类读取系统信息
    /// </summary>
    public class SystemInfo
    {
        private RegistryKey cpu = null;
        private RegistryKey bios = null;
        private RegistryKey network = null;

        /// <summary>
        /// 构造器
        /// </summary>
        public SystemInfo()
        {
            cpu = Registry.LocalMachine.OpenSubKey(@"HARDWARE\DESCRIPTION\System\CentralProcessor\0");
            bios = Registry.LocalMachine.OpenSubKey(@"HARDWARE\DESCRIPTION\System");
            network = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards\1");
        }

        /// <summary>
        /// CPU描述
        /// </summary>
        public string GetProcessorName()
        {
            return cpu.GetValue("ProcessorNameString").ToString();
        }

        /// <summary>
        /// CPU序列号
        /// </summary>
        public string GetProcessorIdentifier()
        {
            return cpu.GetValue("Identifier").ToString();
        }

        /// <summary>
        /// 获取CPU制造商
        /// </summary>
        /// <returns></returns>
        public string GetVendorIdentifier()
        {
            return cpu.GetValue("VendorIdentifier").ToString();
        }

        /// <summary>
        /// 获取CPU速度
        /// </summary>
        /// <returns></returns>
        public string GetProcessorFrequency()
        {
            return cpu.GetValue("~MHz").ToString() + " MHz";
        }

        /// <summary>
        /// 获取系统BIOS标识号
        /// </summary>
        /// <returns></returns>
        public string GetBiosIdentifier()
        {
            return bios.GetValue("Identifier").ToString();
        }

        /// <summary>
        /// 获取系统BIOS版本信息
        /// </summary>
        /// <returns></returns>
        public string GetSystemBiosVersion()
        {
            return ((string[])bios.GetValue("SystemBiosVersion"))[0].ToString();
        }

        /// <summary>
        /// Get video biso version
        /// </summary>
        /// <returns></returns>
        public string GetVideoBiosVersion()
        {
            return ((string[])bios.GetValue("VideoBiosVersion"))[0].ToString();
        }

        ///<summary>
        /// Get video bios date
        ///</summary>
        ///<returns></returns>
        public string GetVideoBiosDate()
        {
            return bios.GetValue("VideoBiosDate").ToString();
        }

        ///<summary>
        /// 获取网卡信息
        ///</summary>
        ///<returns></returns>
        public string GetNetworkCardsInfo()
        {
            return network.GetValue("Description").ToString();
        }
    }
}